import axios from "axios";
export default ({
  namespaced: true,
  state: {
    currentPage: 1,
    pageSize: 2,
    pageData: {
      goodsData: [],
      total: 0,
      pages: 0
    },
    categoryId:'',
  },
  mutations: {
    getGoods(state, payload) {
      state.pageData = payload
    },
    getUsers(state, payload) {
      state.pageData = payload
    },
    changePage(state,newcurrentPage){
      state.currentPage=newcurrentPage;
    },
    changeSize(state,newpageSize){
      state.pageSize=newpageSize;
    }
    // nextPage(state) {
    //   state.currentPage++;
    // },
    // prevPage(state) {
    //   state.currentPage--;
    //   // console.log(state.currentPage)
    // },

  },
  actions: {
    getGoodsAsync(context) {
      const { currentPage, pageSize,categoryId } = context.state;
      axios.get("/goods/getGoods", { params: { currentPage, pageSize,categoryId } }).then(res => {
        //调用mutations的方法
        context.commit('getGoods', res.data);
      })
    },
    getUsersAsync(context) {
      const { currentPage, pageSize } = context.state;
      axios.get("/users", { params: { currentPage, pageSize } }).then(res => {
        //调用mutations的方法
        context.commit('getGoods', res.data);
      }),
      console.log(context.state.pageData)
    },
    changePageAsync(context,newcurrentPage) {
      context.commit('changePage',newcurrentPage)
      console.log(context.state.currentPage)
    },
    changeSizeAsync(context,newpageSize) {
      context.commit('changeSize',newpageSize)
      console.log(context.state.pageSize)
    },

  },
  modules: {
  }
})  
